package com.akkainaction.remote.event;

import akka.actor.*;
import com.typesafe.config.ConfigFactory;

public class RemoteClientActor extends UntypedActor {

    @Override
    public void onReceive(Object message) throws Exception {
        if(message instanceof String){
            if("talk".equals(message)){
                System.out.println(message);
                ActorSelection selection = getContext().actorSelection("akka.tcp://sys@127.0.0.1:2553/user/remoteServer");
                selection.tell("hello remoteActor", getSelf());
            }else {
                System.out.println(message);
            }
        }else {
            unhandled(message);
        }
    }

    public static void main(String[] args) {
        ActorSystem system = ActorSystem.create("sysCli", ConfigFactory.load("remote-cli.conf") );
        system.actorOf(Props.create(MonitorActor.class),"monitor");
        ActorRef actorRef = system.actorOf(Props.create(RemoteClientActor.class), "clientActor");
        actorRef.tell("talk", ActorRef.noSender());
    }
}
